package leetcode.code1052;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;
//执行用时：2 ms, 在所有 Java 提交中击败了99.55%的用户
//
//内存消耗：43.6 MB, 在所有 Java 提交中击败了5.03%的用户
//
//通过测试用例：78 / 78
public class Solution implements IDebug {

	public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
		int len = customers.length;
		int[] sums = new int[len + 1];
		int index = 0;
		for (int i = 1; i <= len; i++) {
			sums[i] = grumpy[index = i - 1] == 1 ? sums[index] : customers[index] + sums[index];
		}
		int r = 0;
		int sumx = 0;
		while (r < minutes && r < len) {
			sumx += customers[r++];
		}
		int ans = sumx + sums[len] - sums[r];
		int l = 0;
		while (r < len) {
			sumx += customers[r++];
			sumx -= customers[l++];
			ans = Math.max(ans, sumx + sums[len] - sums[r] + sums[l]);
		}
		return ans;
	}

	@Override
	public void debug1() {
		HelpDebug.compare(16, this.maxSatisfied(HelpDebug.str2array3("[1,0,1,2,1,1,7,5]"), HelpDebug.str2array3("[0,1,0,1,0,1,0,1]"), 3));

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
